import time
import asyncio
import functools

now = lambda: time.time()


async def do_some_work(x):
    print('Waiting: ', x)
    return 'Done after {}s'.format(x)


def callback1(future):
    print('Callback: ', future.result())


def callback2(t, future):
    print('Callback:', t, future.result())


if __name__ == '__main__':
    start = now()

    coroutine = do_some_work(2)
    loop = asyncio.get_event_loop()
    task = asyncio.ensure_future(coroutine)

    task.add_done_callback(callback1)
    task.add_done_callback(functools.partial(callback2, 2))

    loop.run_until_complete(task)

    print('TIME: ', now() - start)
